<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
		<table   id="buy"   width="380"      border="" cellspacing="" cellpadding="">
			<thead>
				<td><input type="checkbox" name="" id="" value="" />全选 </td>
				<th>Header</th>
				<th>Header</th>
				<th>Header</th>
				<th>Header</th>
				<th>操作</th>
			</thead>
			<tbody>
			<tr>
				<td><input type="checkbox" name="" id="" value="1" /> </td>
				<td>Data</td>
				<td>50</td>
				<td><input size="3" type="text"/></td>
				<td>50</td>
				<td><input type="button" name="" id="" value="删除"  onclick="del(this)"/> </td>
			
			</tr>
			<tr>
				<td><input type="checkbox" name="" id="" value="1" /> </td>
				<td>Data</td>
				<td>30</td>
				<td><input size="3" type="text"/></td>
				<td>30</td>
				<td><input type="button" name="" id="" value="删除" onclick="del(this)"/></td>
				</tr>
			</tbody>
		</table>
				<td><input type="button" name="" id="" value="添加" onclick="add()"/> </td>
				<td><input type="button" name="" id="" value="删除"  onclick="del(this)"/> </td>
		<script type="text/javascript">
			var buy=document.getElementById("buy");
				function add() {
				//				console.log(buy.rows);
				var row = buy.insertRow(1);
				var cell1 = row.insertCell(0);
				cell1.innerHTML = '<input type="checkbox"/>';
				var cell2 = row.insertCell(1);
				cell2.innerHTML = "产品名称" + row.rowIndex;
				var cell3 = row.insertCell(2);
				var dj = parseInt(Math.random() * 2000);
				cell3.innerHTML = dj;
				var cell4 = row.insertCell(3);
				cell4.innerHTML = '<input type="text" size="3" value="1"/>'
				var cell5 = row.insertCell(4);
				cell5.innerHTML = dj;
				var cell6 = row.insertCell(5);
				cell6.innerHTML = "<input type='button' value='删除' onclick='del(this)' />"
				console.log(row.cells);
				console.log(row.rowIndex);
			}
       function del(t){
       		buy.deleteRow(t.parentNode.parentNode.rowIndex);

       }
		</script>
		
		
		
	</body>

</html>